include $(TOPDIR)/rules.mk

PKG_NAME:=webif-iw-lua-ipbx-ast1.4-mini
PKG_VERSION:=0.0
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_BUILD_DEPENDS:=+lua/host

include $(INCLUDE_DIR)/package.mk

define Package/webif-iw-lua-ipbx-ast1.4-mini
  SECTION:=admin
  CATEGORY:=Administration
  SUBMENU:=webif
  DEPENDS:=+webif +webif-iw-lua
  TITLE:=ipbx Configuration Script in LUA for X-Wrt 
endef

define Build/Prepare
	$(call Build/Prepare/Default)
##	$(CP) -a files $(PKG_BUILD_DIR)
	$(CP) -a files ipkg/* $(PKG_BUILD_DIR)
	find $(PKG_BUILD_DIR)/files -name 'CVS' -o -name '.svn' -o -name '*~' | $(XARGS) rm -rf
endef

define Build/Configure
endef

define Build/Compile
	find $(PKG_BUILD_DIR)/files -type f -name '*.lua' -exec $(STAGING_DIR_HOST)/bin/luac -s -o {} {} \;
endef

define Package/webif-iw-lua-ipbx-ast1.4-mini/install
	$(CP) -a $(PKG_BUILD_DIR)/files/* $(1)/
	$(INSTALL_DIR) $(1)/www/cgi-bin/webif/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/www/cgi-bin/webif/* $(1)/www/cgi-bin/webif/
	mkdir -p $(1)/CONTROL
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/ast1.4-mini.postinst $(1)/CONTROL/postinst
endef

$(eval $(call BuildPackage,webif-iw-lua-ipbx-ast1.4-mini))
